package thomas.javase.map;

import org.junit.Assert;
import org.junit.Test;
import thomas.javase.java8.entity.People;

import java.util.LinkedHashMap;
import java.util.Map;

public class MapTest {

    /**
     * sometimes the Map.get(String key) not work, it can't get the value out, null returned
     * I have run 20 times for below, all got the correct result
     * so, I guess, maybe it's memory problem when I met the problem
     * but when i restart the PC, the problem still there
     * After double check, and found the problem is because the key has set to "UKTR ", i.e. there is a unexpected space after UKTR, it should be "UKTR"
     */
    @Test
    public void  testLinkedHashMap(){
        Map<String, People> map = new LinkedHashMap<>();
        map.put("TWTR", new People("Thomas", 30));
        map.put("UKTR", new People("Linda", 20));

        String country = "TWTR";
        System.out.println(map.get(country).getName());
        Assert.assertEquals("Thomas", map.get(country).getName());
        Assert.assertEquals("Linda", map.get("UKTR").getName());
    }
}
